# coding=utf-8
import time
from threading import Thread

basket = 20

a = 0


class work(Thread):
    workername = ""
    workercount = 0
    workermoney = 0

    def run(self) -> None:
        global basket
        global money
        global a
        while True:
            if a == 6:
                self.workermoney = self.workercount * 1.5
                print(self.workername, "做了", self.workercount, "个蛋挞，赚了", self.workermoney, "块钱")
                break
            elif basket < 500 and a != 6:
                self.workercount = self.workercount + 1
                basket = basket + 1
                print(self.workername, "做了一个蛋挞，篮子还剩", 500 - basket, "个空位")
            elif basket  == 500:
                print("篮子满了厨师们休息3秒")
                time.sleep(3)
                break
class User(Thread):
    username = ""
    count = 0
    time = 0
    money = 500000

    def run(self) -> None:
        global basket
        global a
        while True:
            if basket  > 0 and self.money >= 5:

                self.money = self.money - 5
                self.count = self.count + 1
                # time.sleep(self.time)
                print(self.username, "成功抢了一个蛋挞,还剩", basket , "个蛋挞！，钱包还剩", self.money, "块钱")
            elif basket  <= 0:
                time.sleep(4)
                print(self.username, "蛋挞没了等待4秒")
                continue
            elif self.money == 0:
                print("钱包空了", self.username, "抢蛋挞结束")
                print(self.username, "总共抢了", self.count, "个蛋挞！")
                a = a + 1
                break


w1 = work()
w2 = work()
w3 = work()
w1.workername = "张角"
w2.workername = "张宝"
w3.workername = "张梁"
p1 = User()
p2 = User()
p3 = User()
p4 = User()
p5 = User()
p6 = User()
p1.username = "刘备"
p1.time = 0.1
p2.username = "关羽"
p2.time = 0.1
p3.username = "张飞"
p3.time = 0.1
p4.username = "赵云"
p4.time = 0.1
p5.username = "马超"
p5.time = 0.1
p6.username = "黄忠"
p6.time = 0.1
w1.start()
w2.start()
w3.start()
p1.start()
p2.start()
p3.start()
p4.start()
p5.start()
p6.start()
